function [metaboliteKEGGID, cost]= get_kegg_id_by_metName(metabolitesNames, treshhold)

    cost = 0;
    costForEmptyID = 15;
    costForIDOutOfTreshhold = 10;
    metaboliteKEGGID = '';
    if ~isempty(metabolitesNames)
        metaboliteName = regexprep(metabolitesNames,'_','%20');
        metaboliteName = strtrim(metaboliteName);
        url=strcat('http://rest.kegg.jp/find/compound/',metaboliteName);
        returnData = urlread(url);
        returnDataLinesArray = strtrim(regexp(returnData, '\n', 'split'));
        returnDataLinesArray(cellfun(@isempty,returnDataLinesArray)) = [];
        if length(returnDataLinesArray) == 1
            metaboliteData = returnDataLinesArray{1,1};
            metaboliteKEGGID = metaboliteData(5:10); 
        elseif length(returnDataLinesArray) > 1
            costArray = [];
            for i = 1:length(returnDataLinesArray)
                metaboliteNames = returnDataLinesArray{i}(11:length(returnDataLinesArray{i}));
                metaboliteNamesArray = strtrim(regexp(metaboliteNames,';','split'));
                metabioliteCost = [];
                for y = 1:length(metaboliteNamesArray)
                    metabioliteCost = [metabioliteCost, edit_distance_in_strings(upper(metaboliteName), upper(metaboliteNamesArray{y}))];
                end
                costArray=[costArray,min(metabioliteCost)];
            end
            [c, ind_a] = intersect(costArray,min(costArray));

            if c < treshhold
                 metaboliteKEGGID = returnDataLinesArray{ind_a}(5:10); 
                 cost = c;
            else
                cost = costForIDOutOfTreshhold;
                metaboliteKEGGID = '';
            end
        else
             cost = costForEmptyID;
             metaboliteKEGGID = '';
        end
    else
        cost = costForEmptyID;
    end
end